/***************************************************************************
 创建者：       hualei
 开始时间：   2018.09.10
 copyright:(C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************/
#include "modbusreadinstructiondelegate.h"
#include <QDebug>

ModbusReadInstructionDelegate::ModbusReadInstructionDelegate(QWidget *parent)
    : QObject(parent)
{
}

void ModbusReadInstructionDelegate::initView()
{
    qDebug() << "ModbusReadInstructionDelegate ==== initView()";
    modbusReadInstructionView->noteStr = "(No noteStr!)";
    modbusReadInstructionView->modbusId = "1";
    modbusReadInstructionView->modbusType = E_MODBUS_TYPE_INTERNET_MASTER;
    modbusReadInstructionView->regAddress = 1;
    modbusReadInstructionView->regReadValue = 1;
    modbusReadInstructionView->JMP_LB_Value = "1";
}

void ModbusReadInstructionDelegate::cleanNoteSlot()
{
    modbusReadInstructionView->noteStr.clear();
    qDebug() << "ModbusReadInstructionView Clean Note!";
}

void ModbusReadInstructionDelegate::finishEditInstructionSlot()
{
     QString str = "MODBUS_READ";

     str += " ,R[" + QString::number(modbusReadInstructionView->regReadValue) + "], ";
     str += QString::number(modbusReadInstructionView->regAddress) + ",";
     str += modbusReadInstructionView->modbusId + ", ";

     QString modbusType;
     QString modbusMode;

     if(modbusReadInstructionView->modbusType == E_MODBUS_TYPE_INTERNET_MASTER)
     {
         modbusType = tr("INTERNET, ");
         modbusMode = "MASTER, ";
     }
     else if(modbusReadInstructionView->modbusType == E_MODBUS_TYPE_INTERNET_SLAVE)
     {
         modbusType = "INTERNET, ";
         modbusMode = "SLAVE, ";
     }
     else if(modbusReadInstructionView->modbusType == E_MODBUS_TYPE_RS485_MASTER)
     {
         modbusType = "RS485, ";
         modbusMode = "MASTER, ";
     }
     else if(modbusReadInstructionView->modbusType == E_MODBUS_TYPE_RS485_SLAVE)
     {
         modbusType = "RS485, ";
         modbusMode = "SLAVE, ";
     }

     str += modbusType + modbusMode;
     str += "JMP LB[" + modbusReadInstructionView->JMP_LB_Value + "] ";

     qDebug() << "ModbusReadInstructionDelegate::finishEditInstructionSlot() === noteStr:" << modbusReadInstructionView->noteStr;
     str += "//" + modbusReadInstructionView->noteStr;

     modbusReadInstructionView->instruction = str;
}
